/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package com.comunicacion2.model;

import com.comunicacion2.heatmap.Location;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.TreeMap;

/**
 *
 * @author LangTecnologia
 */
public final class FingerprintsManager {
    
    public static Map<Location, Integer> getIntensityLocationMap(List<Fingerprint> fingerprints) {

		Map<Location, Integer> map = new TreeMap<Location, Integer>();

		for (Fingerprint fingerprint : fingerprints) {

			int x = Integer.valueOf(fingerprint.getX());
			int y = Integer.valueOf(fingerprint.getY());
			Location location = new Location(x, y);

			int value = Integer.valueOf(fingerprint.getIntensidad());
			map.put(location, value);
		}

		return map;
	}
    
    public static List<Fingerprint> simulateFingerprints(PathLossModel model, List<Fingerprint> fingerprints) {
        
        List<Fingerprint> simulation = new ArrayList<Fingerprint>();
        
        for (Fingerprint fingerprint : fingerprints) {
            
            int x = Integer.valueOf(fingerprint.getX());
            int y = Integer.valueOf(fingerprint.getY());
            
            double distance = getDistance(x, y);
            
            if(distance > 0){
                        
                int intensity = model.calculateIntensity(distance);

                Fingerprint simulatedFingerprint = new Fingerprint(fingerprint.getId(), fingerprint.getX(), fingerprint.getY(), String.valueOf(intensity));

                simulation.add(simulatedFingerprint);
            }
        }
        
        return simulation;
    }
    
    private static double getDistance(int x, int y){
        
        double hypotenuse = Math.sqrt( (Math.pow(x, 2) + Math.pow(y,2)));
        
        return hypotenuse;
    }
}
